package stack_queue.leetcode.Leetcode;

import java.util.Stack;

/**
 * @author shkstart
 * @create 2022-10-11-21:35
 */
public class Num155 {

    private Stack<Integer> data;
    private Stack<Integer> help;


        public Num155() {
            data = new Stack<>();
            help = new Stack<>();

        }

        public void push(int val) {

            data.push(val);
            if(help.isEmpty()||help.peek()>=val){
                help.push(val);
            }


        }

        public void pop() {

//            int x = data.peek();
//            if(x==help.peek()){
            if(data.peek().equals(help.peek())){
                help.pop();
            }
            data.pop();


        }

    @Override
    public String toString() {
        return "Num155{" +
                "data=" + data +
                ", help=" + help +
                '}';
    }

    public int top() {
            return data.peek();
        }

        public int getMin() {
            return help.peek();
        }

    public static void main(String[] args) {
        Num155 num155 = new Num155();
        num155.push(512);
        num155.push(-1024);
        num155.push(-1024);
        num155.push(512);
        num155.pop();
        System.out.println("最小值"+num155.getMin());

        num155.pop();

        System.out.println("最小值"+num155.getMin());

        num155.pop();

        System.out.println("最小值"+num155.getMin());


    }
}
